<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function Bank() {
        var n = window.prompt();
        var arr = n.split('');
        console.log(arr);
        if (arr.length <= 4) {
          console.log(Fourin(arr));
        } else if (arr.length > 4 && arr.length <= 8) {
          var arr1 = arr.slice(-4);
          var arr2 = arr.slice(0, -4);
          console.log(arr1, arr2);
          if (arr1[0] == 0) {
            console.log(Fourin(arr2) + '万零' + Fourin(arr1));
          } else {
            console.log(Fourin(arr2) + '万' + Fourin(arr1));
          }
        } else if (arr.length > 8 && arr.length <= 10) {
          var arr1 = arr.slice(-4);
          var arr2 = arr.slice(-8, -4);
          var arr3 = arr.slice(0, -8);
          console.log(arr1, arr2, arr3);
          if (arr1[0] !== '0' && arr2[0] !== '0') {
            console.log(
              Fourin(arr3) + '亿' + Fourin(arr2) + '万' + Fourin(arr1)
            );
          } else if (arr1[0] == '0' && arr2[0] !== '0') {
            console.log(
              Fourin(arr3) + '亿' + Fourin(arr2) + '万零' + Fourin(arr1)
            );
          } else if (arr1[0] !== '0' && arr2[0] == '0') {
            console.log(
              Fourin(arr3) + '亿零' + Fourin(arr2) + '万' + Fourin(arr1)
            );
          } else if (arr1[0] == '0' && arr2[0] == '0') {
            console.log(
              Fourin(arr3) + '亿零' + Fourin(arr2) + '万零' + Fourin(arr1)
            );
          }
        } else {
          alert('请输入合法数字');
          return;
        }
      }
      function Fourin(n) {
        var add = '';
        var n = n;
        switch (n.length) {
          case 1:
            return translate(n[0]);
          case 2:
            return translate(n[0]) + '十' + translate(n[1]);
          case 3:
            return translate(n[0]) + '百' + translate(n[1]) != 0
              ? translate(n[1]) + '十'
              : '零' + translate(n[2]);
          case 4:
            return n[0] != 0
              ? translate(n[0]) +
                  '千' +
                  translate(n[1]) +
                  '百' +
                  translate(n[2]) +
                  '十' +
                  translate(n[3])
              : translate(n[1]) +
                  '百' +
                  translate(n[2]) +
                  '十' +
                  translate(n[3]);
        }
        return add;
      }
      function translate(par) {
        switch (par) {
          case '0':
            return '零';
          case '1':
            return '一';
          case '2':
            return '二';
          case '3':
            return '三';
          case '4':
            return '四';
          case '5':
            return '五';
          case '6':
            return '六';
          case '7':
            return '七';
          case '8':
            return '八';
          case '9':
            return '九';
        }
      }
      Bank();
    </script>
  </body>
</html>
